package com.lyf.juc.practice.threadlocal;

/**
 * @author LYF
 * @date 2022/7/11
 */
class Phone{
    int count = 0;
    volatile int count2 = 0;
    ThreadLocal<Integer> threadLocal = ThreadLocal.withInitial(()->0);

    void sale(){
        count++;
        count2++;
        threadLocal.set(threadLocal.get()+1);
        System.out.println(count+"::"+count2+"::"+threadLocal.get());
    }
}

public class ThreadLocalTests {

    public static void main(String[] args) {
        Phone phone = new Phone();
        for(int i=0;i<5;i++){
            new Thread(()->{
                phone.sale();
            },"thread"+i).start();
        }
    }
}
